package com.teamfractal.fracdustry.common.integration.jei;

import com.teamfractal.fracdustry.common.Fracdustry;
import com.teamfractal.fracdustry.common.data.recipes.init.FDRecipeTypes;
import com.teamfractal.fracdustry.common.integration.jei.categories.OreProcessorRecipeCategory;
import mezz.jei.api.IModPlugin;
import mezz.jei.api.JeiPlugin;
import mezz.jei.api.registration.IRecipeCategoryRegistration;
import mezz.jei.api.registration.IRecipeRegistration;
import net.minecraft.client.Minecraft;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.crafting.RecipeManager;

import javax.annotation.Nonnull;
import java.util.Objects;
import java.util.stream.Collectors;

@JeiPlugin
public class FracdustryJei implements IModPlugin {
    @Nonnull
    @Override
    public ResourceLocation getPluginUid() {
        return new ResourceLocation(Fracdustry.MODID, "jei_plugin");
    }

    @Override
    public void registerCategories(IRecipeCategoryRegistration registration) {
        registration.addRecipeCategories
                (new OreProcessorRecipeCategory(registration.getJeiHelpers().getGuiHelper()));
    }

    @Override
    public void registerRecipes(IRecipeRegistration registration) {
        RecipeManager rm = Objects.requireNonNull(Minecraft.getInstance().level).getRecipeManager();
        registration.addRecipes(rm.getAllRecipesFor(FDRecipeTypes.recipeOreProcessor).stream()
                        .filter(Objects::nonNull).collect(Collectors.toList()),
                OreProcessorRecipeCategory.UID);
    }
}
